package elion.com.theElion.fragmentLandData;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.IconHintView;

import elion.com.elion.R;
import elion.com.theElion.activityMain.Me_AboutActivity;
import elion.com.theElion.activityMain.Me_ContectActivity;
import elion.com.theElion.util.adapter.MyPagerAdapter;

public class SelectFragment extends Fragment implements NavigationView.OnNavigationItemSelectedListener
{


    private RollPagerView pv_imgs;
    private View view;

    public SelectFragment()
    {
    }


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.fragment_select, container, false);
//        Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
//        ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);

        findView();



        DesertSelectFragment desertSelectFragment = DesertSelectFragment.newInstance(1);
        android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction =fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fg_container,desertSelectFragment);
        fragmentTransaction.commit();



//        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
//                getActivity(), drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//        drawer.setDrawerListener(toggle);
//        toggle.syncState();
//
//        drawer.setDrawerListener(new DrawerLayout.DrawerListener()
//        {
//            @Override
//            public void onDrawerSlide(View drawerView, float slideOffset)
//            {
//                //获取屏幕的宽高
//                WindowManager manager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
//                Display display = manager.getDefaultDisplay();
//                //设置右面的布局位置  根据左面菜单的right作为右面布局的left   左面的right+屏幕的宽度（或者right的宽度这里是相等的）为右面布局的right
//                right.layout(navigationView.getRight(), 0, navigationView.getRight() + display.getWidth(), display.getHeight());
//            }
//            @Override
//            public void onDrawerOpened(View drawerView) {
//
//            }
//            @Override
//            public void onDrawerClosed(View drawerView) {
//
//            }
//            @Override
//            public void onDrawerStateChanged(int newState) {
//
//            }
//        });



        // Inflate the layout for this fragment
        return view;
    }

    public void onButtonPressed(Uri uri)
    {
    }

    @Override
    public void onAttach(Context context)
    {
        super.onAttach(context);
    }

    @Override
    public void onDetach()
    {
        super.onDetach();
    }
    public void findView()
    {
        pv_imgs = (RollPagerView) view.findViewById(R.id.datashow_pv_imgs);
        pv_imgs.setAdapter(new MyPagerAdapter());
        pv_imgs.setHintView(new IconHintView(getActivity(), R.drawable.hint_pv_circle_selected, R.drawable.hint_pv_circle_normal));

    }

    public boolean onNavigationItemSelected(MenuItem item)
    {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        Intent intent = null;
//        if (id == R.id.nav_camera)
//        {
//            intent = new Intent(getActivity(), SelectLandActivity.class);
//            // Handle the camera action
//        }
//        else if (id == R.id.nav_gallery)
//        {
//            intent = new Intent(getActivity(), ServiceFragment.class);
//        }
//        else if (id == R.id.nav_slideshow)
//        {
//            intent = new Intent(getActivity(), WarningFragment.class);
//        }
//        else if (id == R.id.nav_manage)
//        {
//            intent = new Intent(SeedActivity.this, FamilyFragment.class);
//        }
        if (id == R.id.nav_send)
        {
            intent = new Intent(getActivity(), Me_ContectActivity.class);
        }
        else if (id == R.id.nav_about)
        {
            intent = new Intent(getActivity(), Me_AboutActivity.class);
        }
        if (intent != null)
        {
            startActivity(intent);
        }

        DrawerLayout drawer = (DrawerLayout) view.findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}
